package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Book1;
import com.ruoyi.system.service.IBook1Service;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图书管理Controller
 * 
 * @author dyl
 * @date 2023-04-17
 */
@Controller
@RequestMapping("/system/book")
public class Book1Controller extends BaseController
{
    private String prefix = "system/book";

    @Autowired
    private IBook1Service book1Service;

    @RequiresPermissions("system:book:view")
    @GetMapping()
    public String book()
    {
        return prefix + "/book";
    }

    /**
     * 查询图书管理列表
     */
    @RequiresPermissions("system:book:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Book1 book1)
    {
        startPage();
        List<Book1> list = book1Service.selectBook1List(book1);
        return getDataTable(list);
    }

    /**
     * 导出图书管理列表
     */
    @RequiresPermissions("system:book:export")
    @Log(title = "图书管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Book1 book1)
    {
        List<Book1> list = book1Service.selectBook1List(book1);
        ExcelUtil<Book1> util = new ExcelUtil<Book1>(Book1.class);
        return util.exportExcel(list, "图书管理数据");
    }

    /**
     * 新增图书管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存图书管理
     */
    @RequiresPermissions("system:book:add")
    @Log(title = "图书管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Book1 book1)
    {
        return toAjax(book1Service.insertBook1(book1));
    }

    /**
     * 修改图书管理
     */
    @RequiresPermissions("system:book:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Book1 book1 = book1Service.selectBook1ById(id);
        mmap.put("book1", book1);
        return prefix + "/edit";
    }

    /**
     * 修改保存图书管理
     */
    @RequiresPermissions("system:book:edit")
    @Log(title = "图书管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Book1 book1)
    {
        return toAjax(book1Service.updateBook1(book1));
    }

    /**
     * 删除图书管理
     */
    @RequiresPermissions("system:book:remove")
    @Log(title = "图书管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(book1Service.deleteBook1ByIds(ids));
    }
}
